package cn.tedu.file;

import java.io.*;
import java.util.Scanner;
/***/
public class TestCopyFile02 {
    public static void main(String[] args) {
        System.out.println("请输入要复制的路径1");
        Scanner scanner = new Scanner(System.in);
        String f1 = scanner.nextLine();
        System.out.println("请输入要复制的路径2");
        String f2 = scanner.nextLine();
        System.out.println("请输入新文件路径");
        String t = scanner.nextLine();

        //创建方法，完成复制
        ZJCopy(f1,f2,t);
    }

    private static void ZJCopy(String f1,String f2,String t) {
        BufferedInputStream in1 = null;
        BufferedInputStream in2 = null;
        BufferedOutputStream out= null;
        try {
            in1 = new BufferedInputStream(new FileInputStream(f1));
            in2 = new BufferedInputStream(new FileInputStream(f2));
            out = new BufferedOutputStream(new FileOutputStream(t,true));
            int b;
            while ((b = in1.read())!=-1){
                out.write(b);
            }
            int b2;
            while ((b2 = in2.read())!=-1){
                out.write(b2);
            }
            System.out.println("恭喜，复制成功");
        } catch (Exception e) {
            System.out.println("抱歉，复制失败");
            e.printStackTrace();
        }
        try {
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            in2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            in1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
